{include file="public/common" /}


<form class="layui-form" id="goods_form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="search_" autocomplete="off" class="layui-input" placeholder="搜索商品名称"
                       value="<?php echo isset($param['search_'])?$param['search_']:''?>">
            </div>
        </div>
        <div class="layui-inline">
            <button type="submit" class="layui-btn">筛选</button>
            <a class="layui-btn" name="export" value="1" onclick="export_data()">导出数据</a>
        </div>
    </div>
</form>

<div>
    <table class="layui-table" width="900px">
        <thead>
        <tr style="text-align: center;">
            <td>商品名</td>
            <td>价格</td>
            <td>库存</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {volist name="list_" id="goods"}
        <tr style="text-align: center;">
            <td> {$goods.goods_name}</td>
            <td> {$goods.price}</td>
            <td> {$goods.stock}</td>
            <td>
                {if condition="$goods.status == 0"} 未审核
                {elseif condition="$goods.status == 1"} 审核通过
                {elseif condition="$goods.status == 2"} 拒绝
                {elseif condition="$goods.status == 3"} 下架
                {else} 未知
                {/if}
            </td>
            <td>
                <div style="width: 50%; margin-top: 5px;">
                    <a class="layui-btn layui-btn-small"
                       href='{:addon_url("admin://goods/edit_")}?goods_id={$goods.id}'> 编辑</a>
                    <a class="layui-btn layui-btn-small" onclick='del_("{$goods.id}")'> 删除 </a>
                    <button class="layui-btn layui-btn-small" onclick="model('/addons/execute/admin-goods-goods_examine_?goods_id={$goods.id}')">审核</button>
                </div>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    {$list_->render()}
</div>

<script>
    /**
     * 导出数据
     */
    function export_data() {
        $data = $('#goods_form').serialize();
        var href = "/addons/execute/admin-goods-list_?export=1&" + $data;
        window.open(href);
        return false;
    }
    /**
     * 删除商品
     * @param id
     * @private
     */
    function del_(id) {
        var s = confirm("确认删除");
        if(s){
            $.ajax({
                url: '{:addon_url("admin://goods/del")}' ,
                dataType: "json",
                async: true,
                data: {
                    "goods_id": id
                },
                type: "post",
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                    }
                    else {
                        layer.alert(res.data, {icon: 5});
                    }
                },
                error: function (xhr, errorText, errorStatus) {
                    alert('fail');
                }
            });
        }
    }
</script>